package xps.and.uudaijia.userclient.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.location.c.e;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.PoiInfo;
import com.bumptech.glide.Glide;
import com.hitomi.cslibrary.CrazyShadow;
import com.hitomi.cslibrary.base.CrazyShadowDirection;
import com.jude.utils.JUtils;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;
import nucleus.factory.RequiresPresenter;
import rx.Subscriber;
import xps.and.uudaijia.userclient.EventBusCommond.EventBusRequestReserveTime;
import xps.and.uudaijia.userclient.R;
import xps.and.uudaijia.userclient.StringCommond;
import xps.and.uudaijia.userclient.data.baen.GXBean;
import xps.and.uudaijia.userclient.data.baen.MapBean;
import xps.and.uudaijia.userclient.data.baen.UrlBean;
import xps.and.uudaijia.userclient.data.baen.YHJBean;
import xps.and.uudaijia.userclient.data.net.UserNetWorks;
import xps.and.uudaijia.userclient.presenter.MainPresenter;
import xps.and.uudaijia.userclient.service.RemoteService;
import xps.and.uudaijia.userclient.util.AppCommond;
import xps.and.uudaijia.userclient.util.CommonUtils;
import xps.and.uudaijia.userclient.util.DensityUtil;
import xps.and.uudaijia.userclient.util.JingtouBack;
import xps.and.uudaijia.userclient.util.MyReceiver;
import xps.and.uudaijia.userclient.view.activity.LoginActivity;
import xps.and.uudaijia.userclient.view.activity.MyOrderActivity;
import xps.and.uudaijia.userclient.view.activity.PersonActivity;
import xps.and.uudaijia.userclient.view.activity.YHJSYActivity;
import xps.and.uudaijia.userclient.view.base.BaseActivity;
import xps.and.uudaijia.userclient.view.fragment.DaijiaInfoPanelFragment;
import xps.and.uudaijia.userclient.view.fragment.MapViewFragment;
import xps.and.uudaijia.userclient.view.fragment.PincheInfoPanelFragment;

@RequiresPresenter(MainPresenter.class)
public class MainActivity extends BaseActivity<MainPresenter> implements MapViewFragment.PinActivationListener, JingtouBack, ViewTreeObserver.OnGlobalLayoutListener, MyReceiver.Message {
    MyReceiver myReceiver;
    @BindView(R.id.tv_daijia)
    TextView tvDaijia;
    @BindView(R.id.actionbar_al)
    AutoRelativeLayout actionbar_al;
    @BindView(R.id.v_indicator_daijia)
    View vIndicatorDaijia;
    @BindView(R.id.al_daijia)
    AutoLinearLayout alDaijia;
    @BindView(R.id.tv_pinche)
    TextView tvPinche;
    @BindView(R.id.v_indicator_pinche)
    View vIndicatorPinche;
    @BindView(R.id.al_pinche)
    AutoLinearLayout alPinche;
    @BindView(R.id.map_container)
    FrameLayout mapContainer;
    @BindView(R.id.container)
    FrameLayout infoPanelContainer;
    MapViewFragment mapViewFragment;
    @BindView(R.id.al_above_service_type)
    AutoLinearLayout al_above_service_type;
    @BindView(R.id.iv_bt_location)
    ImageView iv_bt_location;
    DaijiaInfoPanelFragment daijiaInfoPanelFragment;
    PincheInfoPanelFragment pincheInfoPanelFragment;
    FragmentManager fragmentManager;
    @BindView(R.id.iv_user)
    ImageView ivUser;
    @BindView(R.id.iv_msg)
    ImageView ivMsg;
    @BindView(R.id.v_gap_line)
    View vGapLine;
    EventBusRequestReserveTime eventBusRequestReserveTime;
    String access_token = "";
    String userid = "";
    String startLat;
    String startLng;
    String sijileibie = "1";

    @Override
    protected int getLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void setData() {
        gengxin();
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            MapJingWeiDu();
        }
    };

    private Runnable runnable = new Runnable() {

        public void run() {
            this.update();
            mHandler.postDelayed(this, 1000 * 120);// 间隔120秒
        }

        void update() {
            //刷新msg的内容
        }

    };
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(AppCommond a) {
        if (!AppCommond.check(a)) return;
        for (String activityName : a.getAcNameList()) {
            if (activityName.equals(getClass().getSimpleName())) {
                unreg();
                finish();
                break;
            }
        }
    }

    void unreg() {
        if (EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().unregister(this);
    }
    @Override
    protected void init() {
        ButterKnife.bind(this);
        myReceiver = new MyReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.nangch.broadcasereceiver.MYRECEIVER");
        registerReceiver(myReceiver, intentFilter);
        myReceiver.setMessage(this);
        if (!EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().register(this);
        Intent intent = getIntent();
        access_token = intent.getStringExtra("access_token");
        userid = intent.getStringExtra("userId");

        SharedPreferences sp = JUtils.getSharedPreference();
        if (!TextUtils.isEmpty(sp.getString("User_Access_token", ""))) {
            access_token = sp.getString("User_Access_token", "");
        }
        if (!TextUtils.isEmpty(sp.getString("User_ID", ""))) {
            userid = sp.getString("User_ID", "");
        }

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
            eventBusRequestReserveTime = new EventBusRequestReserveTime();
            if (eventBusRequestReserveTime.getDate().equals(null)) {
                daijiaInfoPanelFragment.tvReservationTime.setText(eventBusRequestReserveTime.getDate() + "");
            }
        }

        if (TextUtils.isEmpty(sp.getString("YHJ", ""))) {
            douserId();
        }
        getHuoDong();
        mapViewFragment = new MapViewFragment();
        CommonUtils.replaceFragment(R.id.map_container, mapViewFragment, getSupportFragmentManager());

        fragmentManager = getSupportFragmentManager();
        daijiaInfoPanelFragment = new DaijiaInfoPanelFragment();
        pincheInfoPanelFragment = new PincheInfoPanelFragment();
        Bundle bundle = new Bundle();
        bundle.putString("access_token", access_token);
        bundle.putString("userid", userid);
        daijiaInfoPanelFragment.setArguments(bundle);
        pincheInfoPanelFragment.setArguments(bundle);
        fragmentManager.beginTransaction()
                .add(R.id.container, pincheInfoPanelFragment, pincheInfoPanelFragment.getClass().getName()).disallowAddToBackStack().commit();

        fragmentManager.beginTransaction()
                .add(R.id.container, daijiaInfoPanelFragment, daijiaInfoPanelFragment.getClass().getName())
                .disallowAddToBackStack().show(daijiaInfoPanelFragment).commit();

        actionbar_al.getViewTreeObserver().addOnGlobalLayoutListener(this);
        mapViewFragment.setPinActionListener(this);
        resetLable();
        vIndicatorDaijia.setVisibility(View.VISIBLE);

        new CrazyShadow.Builder()
                .setContext(this)
                .setDirection(CrazyShadowDirection.BOTTOM)
                .setShadowRadius(JUtils.dip2px(3.3f))
                .setCorner(JUtils.dip2px(10))
                .setBackground(getResources().getColor(R.color.white))
                .setImpl(CrazyShadow.IMPL_FLOAT)
                .action(al_above_service_type);

        mHandler.postDelayed(runnable, 1000 * 60);

        JPushInterface.setAliasAndTags(MainActivity.this, JUtils.getSharedPreference().getString("User_Access_token", "").substring(0, 10), null, mAliasCallback);
    }

    private void hideFrags() {
        daijiaInfoPanelFragment.hide();
        pincheInfoPanelFragment.hide();
    }

    void resetLable() {
        vIndicatorDaijia.setVisibility(View.INVISIBLE);
        vIndicatorPinche.setVisibility(View.INVISIBLE);
    }


    @OnClick({R.id.tv_daijia, R.id.v_indicator_daijia, R.id.al_daijia, R.id.tv_pinche, R.id.v_indicator_pinche, R.id.al_pinche, R.id.map_container, R.id.container, R.id.iv_bt_location, R.id.iv_user, R.id.iv_msg})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_daijia:
                sijileibie = "1";
                MapJingWeiDu();
                toDaijiaMode();
                break;
            case R.id.tv_pinche:
                sijileibie = "2";
                MapJingWeiDu();
                toPincheMode();
                break;
            case R.id.v_indicator_daijia:
                break;
            case R.id.al_daijia:
                break;
            case R.id.al_pinche:
                break;
            case R.id.v_indicator_pinche:
                break;
            case R.id.map_container:
                break;
            case R.id.container:
                break;
            case R.id.iv_bt_location:
                mapViewFragment.recoveryCameraHG();
                break;
            case R.id.iv_user:
                Intent intent = new Intent(MainActivity.this, PersonActivity.class);
                startActivity(intent);
                break;
            case R.id.iv_msg:
                CommonUtils.AppStartActivity(this, MyOrderActivity.class);
                break;
        }
    }

    void toPincheMode() {
        resetLable();
        vIndicatorPinche.setVisibility(View.VISIBLE);
        hideFrags();
        fragmentManager.beginTransaction().show(pincheInfoPanelFragment).commit();
        EventBus.getDefault().post(StringCommond.ON_GLOBALLAYOUT_CHANGES);
        pincheInfoPanelFragment.PCLayout.setVisibility(View.VISIBLE);
    }

    void toDaijiaMode() {
        resetLable();
        vIndicatorDaijia.setVisibility(View.VISIBLE);
        hideFrags();
        fragmentManager.beginTransaction().show(daijiaInfoPanelFragment).commit();
        EventBus.getDefault().post(StringCommond.ON_GLOBALLAYOUT_CHANGES);
    }

    //todo
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }

        mapViewFragment.setPinActionListener(null);
        unregisterReceiver(myReceiver);
        mHandler.removeCallbacks(runnable);

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEventMainThread(String commond) {
        if (commond.equals(StringCommond.ON_GLOBALLAYOUT_CHANGES)) {
            actionbar_al.getViewTreeObserver().addOnGlobalLayoutListener(this);
        } else if (commond.equals(StringCommond.ON_REQUEST_RESERVETIME_DAIJIAFRAGMENT)) {
            getPresenter().chooseReserveTime(this, "代驾");
        } else if (commond.equals(StringCommond.ON_REQUEST_RESERVETIME_PINCHEFRAGMENT)) {
            getPresenter().chooseReserveTime(this, "拼车");
        }
    }

    /**
     * 监听全局layout事件 用来动态改变定位按钮的位置
     * todo  效率有点低 先这样
     */
    public void onGlobalLayout() {
        int y = infoPanelContainer.getMeasuredHeight() + iv_bt_location.getMeasuredWidth() / 2;
        AutoFrameLayout.LayoutParams layoutParams = new AutoFrameLayout.LayoutParams(AutoFrameLayout.LayoutParams.MATCH_PARENT, AutoFrameLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.width =  AutoUtils.getPercentHeightSize(100);
        layoutParams.height = AutoUtils.getPercentHeightSize(100);

        layoutParams.gravity = Gravity.END | Gravity.BOTTOM;
        layoutParams.setMargins(0, 0, iv_bt_location.getMeasuredWidth() / 2, y);
        iv_bt_location.setLayoutParams(layoutParams);

        //及时取消注册
        actionbar_al.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }

    @Override
    public void onPinMoved(final ArrayList<PoiInfo> p) {
        if (p == null || p.size() <= 0) return;
        runOnUiThread(() -> daijiaInfoPanelFragment.tvStartLocation.setText(p.get(0).name));

        Log.e("onPinMoved", p.get(0).name);
        daijiaInfoPanelFragment.startLat = p.get(0).location.latitude + "";
        daijiaInfoPanelFragment.startLng = p.get(0).location.longitude + "";
        if (daijiaInfoPanelFragment.alContractPeriod.getVisibility() == View.GONE) {
            daijiaInfoPanelFragment.getReservation();
        } else {
            daijiaInfoPanelFragment.getDudget();
        }
        startLat = p.get(0).location.latitude + "";
        startLng = p.get(0).location.longitude + "";
        MapJingWeiDu();
        runOnUiThread(() -> pincheInfoPanelFragment.tvStart.setText(p.get(0).name));
        pincheInfoPanelFragment.startLat = p.get(0).location.latitude + "";
        pincheInfoPanelFragment.startLng = p.get(0).location.longitude + "";
        pincheInfoPanelFragment.getPingCHeYG();

        if (pincheInfoPanelFragment.PDLayout.getVisibility() == View.GONE) {
            pincheInfoPanelFragment.getBuPingCHeYG();
        } else {
            pincheInfoPanelFragment.getPingCHeYG();
        }
    }

    @Override
    public void onPinMoveStart() {
        runOnUiThread(() -> daijiaInfoPanelFragment.tvStartLocation.setText("正在获取位置..."));
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        daijiaInfoPanelFragment.onActivityResult(requestCode, resultCode, data);
        pincheInfoPanelFragment.onActivityResult(requestCode, resultCode, data);
    }

    void MapJingWeiDu() {
        mapViewFragment.resetOverlay();
        UserNetWorks.getMapJingWeiDu(startLat + "", startLng + "", sijileibie, new Subscriber<MapBean>() {
                    @Override
                    public void onCompleted() {
                        Log.e("getMapJingWeiDu", "onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(MapBean mapBean) {
                        if (mapBean.getReturn_code().equals("SUCCESS")) {
                            if (mapBean.getReturn_body() != null && mapBean.getReturn_body().size() > 0) {
                                placeMarker(mapBean);
                            }
                        } else if (mapBean.getReturn_code().equals("FAIL")) {
                            JUtils.Toast(mapBean.getReturn_msg());
                        }

                        mapBean.getReturn_body().stream().filter(abc->
                              TextUtils.isEmpty(abc.toString())
                        );
                    }
                }
        );
    }


    void getHuoDong() {
        UserNetWorks.getHuoDong("1", new Subscriber<UrlBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();

            }

            @Override
            public void onNext(UrlBean urlBean) {
                if (urlBean.getMessage().equals("SUCCESS")) {
                    final Dialog bottomDialog = new Dialog(MainActivity.this, R.style.BottomDialog);
                    View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_huodong, null);
                    bottomDialog.setContentView(contentView);
                    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
                    params.width = getResources().getDisplayMetrics().widthPixels - DensityUtil.dp2px(MainActivity.this, 16f);
                    params.bottomMargin = DensityUtil.dp2px(MainActivity.this, 8f);
                    contentView.setLayoutParams(params);
                    bottomDialog.setCanceledOnTouchOutside(true);
                    bottomDialog.getWindow().setGravity(Gravity.CENTER);
                    bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
                    bottomDialog.show();
                    ImageView tupian_Image2 = (ImageView) contentView.findViewById(R.id.tupian_Image);
                    Glide.with(MainActivity.this).load(urlBean.getUrl())
                            .into(tupian_Image2);
                    ImageView tupian_Image = (ImageView) contentView.findViewById(R.id.quxiao_Image);
                    tupian_Image.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            bottomDialog.dismiss();
                        }
                    });
                } else if (urlBean.getMessage().equals("FAIL")) {

                }
            }
        });
    }

    /**
     * 添加markers
     */
    void placeMarker(MapBean mapBean) {
        for (int i = 0; i < mapBean.getReturn_body().size(); i++) {
            MapBean.ReturnBodyBean reb = mapBean.getReturn_body().get(i);
            MapBean.ReturnBodyBean.LatestLocationBean latestLocationBean = reb.getLatest_location();
            Log.e("getMapJingWeiDu", latestLocationBean.toString());
            LatLng locat_endPointA = new LatLng(latestLocationBean.getLatitude(), latestLocationBean.getLongitude());
            if (reb.getWorkState().equals("2")) {
                mapViewFragment.addMarker(locat_endPointA, reb.getEntity_desc().toString());
            }
        }
//        Bundle bundle = new Bundle();
//        bundle.putSerializable("BEAN", mapBean);
//        mapViewFragment.setArguments(bundle);
//        CommonUtils.replaceFragment(R.id.map_container, mapViewFragment, getSupportFragmentManager());
    }


    @Override
    public void getMsg(String getCouponId, String getCouponMoney, String getCouponIdPD) {
        String getCouponIdStr = getCouponId;
        String getCouponMoneyStr = getCouponMoney;
        String getCouponIdPDStr = getCouponIdPD;
        if (getCouponIdStr.equals("0")) {
            daijiaInfoPanelFragment.couponId = "0";
            daijiaInfoPanelFragment.YHJText.setText("优惠劵");
            pincheInfoPanelFragment.couponId = "0";
            pincheInfoPanelFragment.YHJText.setText("优惠劵");
        } else {
            if (getCouponIdPDStr != null) {
                if (getCouponIdPDStr.equals("1")) {
                    daijiaInfoPanelFragment.couponId = getCouponIdStr;
                    daijiaInfoPanelFragment.YHJText.setText(getCouponMoneyStr + "元优惠劵");
                } else {
                    pincheInfoPanelFragment.couponId = getCouponIdStr;
                    pincheInfoPanelFragment.YHJText.setText(getCouponMoneyStr + "元优惠劵");
                }
            }
        }
    }

    public void showCustomize() {
        AlertDialog.Builder customizeDialog =
                new AlertDialog.Builder(MainActivity.this);
        final View dialogView = LayoutInflater.from(MainActivity.this)
                .inflate(R.layout.dialog_dianhua, null);
        TextView textView = (TextView) dialogView.findViewById(R.id.edit_text);
        textView.setText("您的账号在其他地方登录");
        customizeDialog.setTitle("温馨提示");
        customizeDialog.setView(dialogView);
        customizeDialog.setNegativeButton("取消",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        customizeDialog.setPositiveButton("确定",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 获取EditView中的输入内容
                        SharedPreferences sp = JUtils.getSharedPreference();
                        SharedPreferences.Editor spEd = sp.edit();
                        spEd.putString("User_Access_token", "");
                        spEd.putString("User_ID", "");
                        spEd.putString("User_Name", "");
                        spEd.putString("User_Phone", "");
                        spEd.putString("User_Img", "");
                        spEd.putBoolean("User_Login", false);
                        spEd.commit();
                        Intent Logintent = new Intent(MainActivity.this, LoginActivity.class);
                        startActivity(Logintent);
                        Intent Serviceintent = new Intent(MainActivity.this, RemoteService.class);
                        stopService(Serviceintent);
                        finish();
                    }
                });
        customizeDialog.show();
    }

    void douserId() {
        UserNetWorks.getYHJ("", new Subscriber<YHJBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(YHJBean yhjBean) {
                Log.e("YHJBean", yhjBean.toString());
                List<YHJBean.ReturnBodyBean> list = yhjBean.getReturn_body();
                if (list != null && list.size() > 0) {
                    SharedPreferences sp = JUtils.getSharedPreference();
                    SharedPreferences.Editor spEd = sp.edit();
                    spEd.putString("YHJ", "false");
                    spEd.commit();
                    addOrderItem(list.get(list.size() - 1));
                }
            }
        });
    }

    void addOrderItem(YHJBean.ReturnBodyBean yhjBean) {
        final Dialog bottomDialog = new Dialog(MainActivity.this, R.style.BottomDialog);
        View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog, null);
        bottomDialog.setContentView(contentView);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
        params.width = getResources().getDisplayMetrics().widthPixels - DensityUtil.dp2px(MainActivity.this, 16f);
        params.bottomMargin = DensityUtil.dp2px(MainActivity.this, 8f);
        contentView.setLayoutParams(params);
        bottomDialog.setCanceledOnTouchOutside(true);
        bottomDialog.getWindow().setGravity(Gravity.CENTER);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
        bottomDialog.show();
        TextView yuan = (TextView) contentView.findViewById(R.id.yuan);
        yuan.setText(yhjBean.getCouponMoney() + "");
        ImageView QX_img = (ImageView) contentView.findViewById(R.id.QC_Img);
        QX_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomDialog.dismiss();
            }
        });

        ImageView chankanYHJ_Img = (ImageView) contentView.findViewById(R.id.chankanYHJ_Img);
        chankanYHJ_Img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent YHJSYintent = new Intent(MainActivity.this, YHJSYActivity.class);
                startActivity(YHJSYintent);
                bottomDialog.dismiss();
            }
        });
    }

    private final TagAliasCallback mAliasCallback = new TagAliasCallback() {
        @Override
        public void gotResult(int code, String alias, Set<String> tags) {
            String logs;
            switch (code) {
                case 0:
                    logs = "Set tag and alias success极光推送别名设置成功";
                    Log.i("mAliasCallback", logs);
                    break;
                case 6002:
                    logs = "Failed to set alias and tags due to timeout. Try again after 60s.极光推送别名设置失败，60秒后重试";
                    Log.i("mAliasCallback", logs);
                    break;
                default:
                    logs = "极光推送设置失败，Failed with errorCode = " + code;
                    Log.e("mAliasCallback", logs);
                    break;
            }
        }
    };

    void gengxin() {
        UserNetWorks.getGengXin("2", new Subscriber<GXBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();

            }

            @Override
            public void onNext(GXBean gxBean) {
                GXBean.DataBean dataBean = gxBean.getData();
                if (gxBean.getMessage().equals("SUCCESS")) {
                    if (Integer.valueOf(dataBean.getVersion()) > JUtils.getAppVersionCode()) {
                        final AlertDialog.Builder normalDialog =
                                new AlertDialog.Builder(MainActivity.this);
                        normalDialog.setTitle("版本更新");
                        normalDialog.setMessage("请前往应用商店下载");
                        normalDialog.setPositiveButton("确定",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Intent intent = new Intent();
                                        intent.setAction("android.intent.action.VIEW");
                                        Uri content_url = Uri.parse(dataBean.getAndroid_Url());
                                        intent.setData(content_url);
                                        startActivity(intent);
                                    }
                                });
                        normalDialog.setCancelable(false);
                        normalDialog.show();
                    }
                }
            }
        });
    }

    @Override
    public void getShuzhiBack(double sta, double end) {
        LatLng latLng = new LatLng(sta, end);
        mapViewFragment.moveCameraTo(latLng);
        startLat = String.valueOf(sta);
        startLng = String.valueOf(end);
        MapJingWeiDu();
    }


}
